<template>
  <div class="complaint-detail" v-loading="loading" ref="print">
    <el-page-header @back="goBack" content="详情页面" style="font-weight: bold; font-size: 20px"></el-page-header>
    <div class="admin-detail">
      <div class="detail detail-text">
        <div class="detail-title">姓名：</div>
        <div class="detail-content">{{ map.name }}</div>
      </div>
      <div class="detail detail-text">
        <div class="detail-title">联系电话：</div>
        <div class="detail-content">{{ map.telephone }}</div>
      </div>
      <div class="detail detail-textuser">
        <div class="detail-title">投诉人：</div>
        <div class="detail-content">{{ map.username }}</div>
      </div>
      <div class="detail detail-autotime">
        <div class="detail-title">添加时间：</div>
        <div class="detail-content">{{ map.addtime }}</div>
      </div>
      <div class="detail detail-review" style="width: 100%;padding-bottom: 20px;padding-top: 20px">
        <div class="detail-title">评价打分：</div>
        <div class="detail-content"><el-rate v-model="map.review" :max="5" disabled></el-rate></div>
      </div>
      <div class="detail detail-textarea" style="width: 100%;border: none;margin-top: 20px;margin-bottom: 15px">
        <div class="detail-title">投诉内容：</div>
        <div class="detail-content">{{ map.content }}</div>
      </div>
      <div class="detail detail-images">
        <div class="detail-title">上传文件：</div>
        <div class="detail-content images_box" style="display: flex">
          <div v-if="mediaFiles.length > 0" style="display: flex">
            <div v-for="file in mediaFiles" :key="file.id" class="complainImage" @click="handlePreview(file)">
              <div v-if="file.type.startsWith('image')" class="image-container">
                <img :src="file.base64" :alt="'Image ' + file.id" class="image" />
                <div class="overlay">
                  <i class="el-icon-zoom-in"></i>
                </div>
              </div>
              <!--            <div v-else-if="file.type.startsWith('video')" class="video-container">-->
              <!--              <video :src="file.base64" controls class="video"></video>-->
              <!--              <div class="overlay">-->
              <!--                <i class="el-icon-zoom-in"></i>-->
              <!--              </div>-->
              <!--            </div>-->
            </div>
          </div>
          <div v-else class="detail-content" style="color: #aaa; font-style: italic;">
            无上传文件
          </div>
        </div>
      </div>
      <div class="detail detail-textarea" style="padding: 20px 0;width: 100%">
        <div class="detail-title">回复内容：</div>
        <div class="detail-content" :class="{ 'no-reply': !map.reply }">
          {{ map.reply || '暂未回复' }}
        </div>
      </div>
    </div>
    <div class="mt10">
      <el-button style="letter-spacing: 2px; font-weight: bold; font-size: 18px" type="default" class="hidePrint"
        @click="$router.go(-1)">
        返回
      </el-button>
      <el-button
        style="letter-spacing: 2px; font-weight: bold; font-size: 18px; background-color: #659ab1; border-color:#659ab1;"
        type="success" class="hidePrint" @click="$print">
        打印本页
      </el-button>
    </div>
    <el-dialog :visible.sync="dialogVisible">
      <img v-if="isImage" :src="dialogImageUrl" width="100%" alt="" />
      <video v-else :src="dialogImageUrl" width="100%" controls></video>
    </el-dialog>
  </div>
</template>

<style type="text/scss" scoped lang="scss">
.complaint-detail {
  background-color: #fff;
  border-radius: 10px;
  padding: 18px;

  ::v-deep .el-page-header__title {
    font-size: 18px;
    color: #6d737b;
  }

  ::v-deep .el-page-header__title:hover {
    color: #bfc1c4;
  }

  ::v-deep .el-page-header__content {
    font-size: 22px;
    color: #7fabbe;
  }

  .admin-detail {
    display: flex;
    flex-wrap: wrap;
    margin-top: 30px;

    .detail {
      width: 25%;
      padding: 5px;
      display: flex;
      margin-bottom: 10px;
      border-bottom: 1px solid #DEDEDE;
      padding-bottom: 20px;
      padding-top: 20px;

      .detail-title {
        width: 120px;
        text-align: right;
        flex-shrink: 0;
        font-size: 18px;
        font-weight: bold;
        letter-spacing: 1px;
      }

      .detail-content {
        flex-grow: 1;
        font-size: 18px;
        letter-spacing: 1px;
      }
    }

    .detail.detail-images {
      width: 100%;
      flex-wrap: wrap;
      display: flex;

      .detail-content {
        width: 70%;
        padding: 0;
        border-radius: 10px;
        border-color: #fff;

        ::v-deep .images_box {
          border-radius: 10px;
          border-color: #fff;
        }

        ::v-deep .complainImage {
          display: flex;
          align-items: center;
          justify-content: center;
          width: 150px;
          height: 150px;
          margin-right: 10px;
          cursor: pointer;
          position: relative;

          .image {
            width: 100%;
            height: 100%;
            object-fit: cover;
            border-radius: 5px;
          }

          .video-container {
            position: relative;
            width: 100%;
            height: 100%;

            .video {
              width: 100%;
              height: 100%;
              object-fit: cover;
              border-radius: 5px;
            }
          }

          .overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            background-color: rgba(0, 0, 0, 0.5);
            opacity: 0;
            transition: opacity 0.3s;
            border-radius: 5px;
            color: white;
            font-size: 24px;
          }

          &:hover .overlay {
            opacity: 1;
          }
        }
      }
    }

    .detail.detail-editor,
    .detail.detail-dataset {
      width: 100%;
      flex-wrap: wrap;

      .detail-title {
        width: 100%;
        padding: 10px;
        margin-top: 10px;
        background: #659ab1;
        color: #ffffff;
        text-align: left;
        border-radius: 7px;
        letter-spacing: 2px;
      }

      .detail-content {
        padding: 10px;
      }
    }

    .detail.detail-textarea .detail-content.no-reply {
      color: #aaa;
      /* 设置较淡的颜色 */
      font-style: italic;
    }
  }

  ::v-deep .el-rate__icon {
    font-size: 27px;
  }
}
</style>

<script>
import api from '@/api';
import { extend } from '@/utils/extend';

export default {
  data() {
    return {
      loading: false,
      map: {},
      mediaFiles: [],
      dialogVisible: false,
      dialogImageUrl: '',
      isImage: false
    };
  },
  props: {
    id: {
      type: [String, Number],
      required: true
    },
  },
  watch: {
    id: {
      handler() {
        this.loadDetail();
      },
      immediate: true
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    loadDetail() {
      if (this.loading) return;
      this.loading = true;
      this.$get(api.complaint.detail, { id: this.id }).then(res => {
        this.loading = false;
        if (res.code == api.code.OK) {
          extend(this, res.data);
          this.mediaFiles = res.data.map.mediaFiles.map(file => ({
            ...file,
            base64: file.base64Image
          }));
        } else {
          this.$message.error(res.msg);
        }
      }).catch(err => {
        this.loading = false;
        this.$message.error(err.message);
      });
    },
    handlePreview(file) {
      this.dialogImageUrl = file.base64;
      this.isImage = file.type.startsWith('image');
      this.dialogVisible = true;
    }
  }
};
</script>
